/**
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package com.zbest.zpay.gw.processor;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import com.zbest.zpay.gw.model.MessageContext;
import com.zbest.zpay.gw.model.MessageDirection;

/**
 * 
 *
 * @author Administrator
 * @version $Id: MessageSenderManager.java, v 0.1 2017-4-23 下午7:20:14
 *          Administrator Exp $
 */
@Service("messageProcessorManager")
public class MessageProcessorManager implements InitializingBean {

    private Map<String, MessageProcessor> processorMap = new HashMap<String, MessageProcessor>();

    @Resource
    private MessageProcessor              messageSender;

    @Resource
    private MessageProcessor              messageReceive;

    public MessageContext process(String channelId, MessageDirection messageDirection,
                                  Map<String, Object> data) {

        MessageProcessor sender = processorMap.get(channelId);
        if (sender == null) {
            if (messageDirection == MessageDirection.SEND) {
                sender = messageSender;
            } else if (messageDirection == MessageDirection.RECEIVE) {
                sender = messageReceive;
            }
        }
        return sender.process(channelId, data);
    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }
}
